import service from "@/utils/request";
import {convertTime} from "@/utils/date";
import {defineComponent, onMounted, reactive, ref} from 'vue'

export default defineComponent({
    name: 'MonitorLog',
    setup(props, ctx) {

      let listData = ref([
        { username: 'jg52', ip: '117.146.117.207', ipAddress: '上海市', description: '登录系统', client: 'Chrome', useTimes: '200', createTime: '2021-07-29 10:23:30'},
        { username: 'jg52', ip: '117.146.117.207', ipAddress: '上海市', description: '新增用户', client: 'Edge', useTimes: '200', createTime: '2021-07-29 10:25:30'},
        { username: 'jg52', ip: '117.146.117.207', ipAddress: '上海市', description: '退出系统', client: 'Firefox', useTimes: '200', createTime: '2021-07-29 10:33:30'},
      ])
      let pageConfig = reactive({
        size: 20,
        pages: 0,
        pageNum: 1
      })

      const pageQuery = async (pageNum, size) => {
        const params = {
          pageSize: size || pageConfig.size,
          pageNo: pageNum || pageConfig.pageNum,
        }
        const res = (await service.get('monitor/logs', {params}))
        listData.value = res.data
        pageConfig.pages = res.pages
        pageConfig.size = res.pageSize
        pageConfig.pageNum = res.pageNum
      }

      const currentChange = async (pageNum) => {
        await pageQuery(pageNum)
      }

      const sizeChange = async (size) => {
        await pageQuery(null, size)
      }

      // onMounted(() => pageQuery())

      return {
        listData,
        pageConfig,
        sizeChange,
        convertTime,
        currentChange
      }
    }
  }
)
